﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using THSLib;using THSERP.BaseProvider;
namespace THSERP.Modules.UserManagement
{
    public partial class guiAddSections : THSERPScreen
    {
        TreeList TreeList = null;

        public guiAddSections()
        {
            InitializeComponent();
        }
        public guiAddSections(TreeList _treeList)
        {
            InitializeComponent();
            this.TreeList = _treeList;
        }

        private void fld_btnCloseSection_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void fld_btnAddSection_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(fld_txtSection.Text))
            {
                MessageBox.Show("The section name can not be empty.", "#Message#", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            ADUserGroupSectionsController objUserGroupSectionsController = new ADUserGroupSectionsController();
            ADUserGroupSectionsInfo objADUserGroupSectionsInfo = (ADUserGroupSectionsInfo)objUserGroupSectionsController.GetObjectByID(Convert.ToInt32(TreeList.FocusedNode.Tag));
            if (objADUserGroupSectionsInfo == null)
            {
                objADUserGroupSectionsInfo = new ADUserGroupSectionsInfo();
                objADUserGroupSectionsInfo.ADUserGroupID = Convert.ToInt32(TreeList.FocusedNode.Tag);
                objADUserGroupSectionsInfo.ADUserGroupSectionName = fld_txtSection.Text;
                objADUserGroupSectionsInfo.ADUserGroupSectionDesc = objADUserGroupSectionsInfo.ADUserGroupSectionName;
                objUserGroupSectionsController.CreateObject(objADUserGroupSectionsInfo);
            }
            else
            {
                objADUserGroupSectionsInfo.ADUserGroupSectionName = fld_txtSection.Text;
                objADUserGroupSectionsInfo.ADUserGroupSectionDesc = fld_txtSection.Text;
                objUserGroupSectionsController.UpdateObject(objADUserGroupSectionsInfo);
            }
            ((UserManagementModule)this.Module).InitializeTreeList(TreeList);
            this.Close();
        }
    }
}